<template>
  <div class="app-container">
    <div class="query">
      <div>
        <el-button size="mini" type="primary" icon="el-icon-plus" circle @click="$api.go('/basic/edit_article')" />
      </div>
      <div>
        <el-button size="mini" icon="el-icon-refresh" circle @click="initList" />
      </div>
    </div>
    <el-table :data="list" border fit highlight-current-row>
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">{{ scope.$index }}</template>
      </el-table-column>
      <el-table-column align="center" label="所属分类id" width="200">
        <template slot-scope="scope">{{ scope.row.cid }}</template>
      </el-table-column>
      <el-table-column align="center" label="排序" width="100">
        <template slot-scope="scope">{{ scope.row.sort }}</template>
      </el-table-column>
      <el-table-column align="center" label="创建时间" width="200">
        <template slot-scope="scope">{{ scope.row.created | parseTime }}</template>
      </el-table-column>
      <el-table-column align="center" label="文章标题" width="180">
        <template slot-scope="scope">{{ scope.row.title }}</template>
      </el-table-column>
      <el-table-column align="center" label="管理" width="100">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" icon="el-icon-edit" circle @click="handleEdit(scope.row)" />
          <el-button size="mini" type="danger" icon="el-icon-delete" circle @click="handleDelete(scope.row)" />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {},
      dialogVisible: false,
      list: [],
      query: { page: 1, size: 20, total: 0 },
      fileList: []
    }
  },
  created() {
    this.initList()
  },
  methods: {
    initList() {
      this.$api.get('/api/basic/article', this.query).then((res) => {
        this.list = res.data
        this.query.total = res.total
      })
    },
    handleSubmit() {
      this.$api.put('/api/basic/article', {}, this.form).then((res) => {
        this.dialogVisible = false
        this.initList()
      })
    },
    handleDelete(row) {
      this.$api.deleteConfirm('/api/basic/article', { id: row.id }).then((res) => {
        this.initList()
      })
    },
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    handlePreview(file) {
      console.log(file)
    },
    handleEdit(row) {
      window.localStorage.setItem('article', JSON.stringify(row))
      this.$api.go('/basic/edit_article')
    }
  }
}
</script>

<style></style>
